package cg.modelo;

public class Player {

	private String name;
	private Board board;
	private Hand hand;

	public Player(String name, Board board) {
		this.name = name;
		this.board = board;
		this.hand = new Hand();
	}

	public void initialDraw() {
		this.hand.add(this.getDeck().initialDraw());
	}

	public void drawCard() {
		this.hand.add(this.getDeck().draw());
	}
	
	public Deck getDeck() {
		return this.board.getDeck();
	}

	public OutOfPlay getOutOfPlay() {
		return this.board.getOutOfPlay();
	}

	public int handSize() {
		return this.hand.size();
	}

	public void drawCard(int quantity) {
		this.hand.add(this.getDeck().draw(quantity));
	}

	public void discardCard() {
		this.getGraveyard().add(this.hand.removeCard());
	}

	public void discardCard(int quantity) {
		this.getGraveyard().add(this.hand.removeCards(quantity));
	}

	public void discardAllCards() {
		this.getGraveyard().add(this.hand.removeAllCards());
	}

	public Cemetery getGraveyard() {
		return this.board.getGraveyard();
	}

	public void removeFromPlayCard() {
		this.getOutOfPlay().add(this.hand.removeCard());
	}

	public void removeFromPlayCard(int quantity) {
		this.getOutOfPlay().add(this.hand.removeCards(quantity));
		
	}

	public void removeFromPlayAllCards() {
		this.getOutOfPlay().add(this.hand.removeAllCards());
	}

	public MonsterZone getMonsterZone() {
		return this.board.getMonsterZone();
	}

	public boolean setCard(Card card, boolean visibility) {
		if(this.hand.hasCard(card)) {
			Card handCard = this.hand.removeCard(card);
			handCard.setVisibility(visibility);
			return (handCard.set(this.board));
		}
		return false;
	}
	
	public boolean summonCard(MonsterCard monsterCard, BattlePosition bp) {
		if(this.hand.hasCard(monsterCard)) {
			Card handCard = this.hand.removeCard(monsterCard);
			return (((MonsterCard) handCard).summon(this.board,bp));
		}
		return false;	
	}
	
	public boolean setCard(Card card) {
		if(this.hand.hasCard(card)) {
			Card handCard = this.hand.removeCard(card);
			return (handCard.set(this.board));
		}
		return false;
	}

	public void addCardToHand(Card card) {
		this.hand.add(card);
	}

	public void addCardToHand(Card card, int quantity) {
		for(int i=0; i<quantity; i++)
			this.hand.add(card);
	}

	public MagicTrapZone getMagicTrapZone() {
		return this.board.getMagicTrapZone();
	}

}
